package py.edu.ucom.cadira.game.event.war;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.game.war.Board;
import py.edu.ucom.cadira.game.war.WarUser;

/**
 * 
 * @author largonet
 * 
 */
public class PlayUserEvent extends WarGameEvent {
    /**
     * @return the mesaId
     */
	
    public Integer getMesaId() {
        return mesaId;
    }

    public PlayUserEvent() {
		
	}

	/**
     * @param mesaId the mesaId to set
     */
    public void setMesaId(Integer mesaId) {
        this.mesaId = mesaId;
    }
    private WarUser user;
    private Board board;
    private Integer mesaId;

    public PlayUserEvent(WarUser user, Board board, Integer mesaId) {
        this.user = user;
        this.board = board;
        this.mesaId = mesaId;
    }

    /**
     * @return Returns the board.
     */
    public Board getBoard() {
        return board;
    }

    /**
     * @param board The board to set.
     */
    public void setBoard(Board board) {
        this.board = board;
    }

    /**
     * @return Returns the user.
     */
    public WarUser getUser() {
        return user;
    }

    /**
     * @param user The user to set.
     */
    public void setUser(WarUser user) {
        this.user = user;
    }

	@Override
	public void fromXML(Document xml) {
		Element root = xml.getRootElement();
		Element playUserNode = root.getChild("PlayUserEvent");
		Element userNode = playUserNode.getChild("usuario");
		user.fromXml(userNode);
		
		Element boardNode = playUserNode.getChild("tablero");
		board.fromXml(boardNode);
	}
	@Override
	public void toXML(Element root) {
		Element playUserNode = new Element("PlayUserEvent");
		Element userNode = user.toXml();
		Element boardNode = new Element("tablero");
		board.toXml(boardNode);
		
		playUserNode.addContent(userNode);
		playUserNode.addContent(boardNode);
		
		root.addContent(playUserNode);
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof PlayUserEvent)) {
			return false;
		}
		PlayUserEvent otherObj = (PlayUserEvent) obj;
		if (otherObj.getUser().equals(getUser())) {
			return true;
		}
		return false;
	}
}
